#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 1000000 + 5;
const int inf = 1e8;
typedef long long ll;

int dp[maxn], a[maxn], pre[maxn];
int n, m;
int getMaxSum()
{
    memset(dp, 0, maxn*4);
    memset(pre, 0, maxn*4);
    int tmp;
    for(int i = 1; i <= m; i++)
    {
        tmp = -inf;
        for(int j = i; j <= n; j++)
        {
            dp[j] = max(dp[j-1], pre[j]) + a[j];
            pre[j]=tmp;
            tmp = max(tmp, dp[j]);
        }
    }
    return tmp;
}
int main()
{
    while(~scanf("%d%d", &m, &n)){
        memset(a, 0, sizeof(a));

        for(int i = 1; i <= n; i++)	scanf("%d", &a[i]);

        printf("%d\n", getMaxSum());	//答案就是最后一轮的最大值
    }
    return 0;
}
